<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            position:relative;
            width: 400px;
            border-bottom: 1px solid #ccc;
            margin: 100px auto;
        }
        .box input{
            width: 370px;
            height: 30px;
            border: 0;
            outline: none;
        }
        .box img{
            position: absolute;
            top: 10px;
            right:30px;
            width: 24px;
        }
    </style>
</head>
<body>
    <div>
        <div class="box">
            <label for="">
                <img src="" alt="" id="eye">
            </label>
            <input type="password" id="pwd">
        </div>
    </div>

    <script>
        //js中代码思路 点击小眼睛之后 修改眼睛的图片 将type类型从password改成text 
        // 用flag=0表示当前处于密码框 flag=1表示当前处于文本框修改成密码框
        // 先获取元素
        var eye = document.getElementById('eye');
        var pwd = document.getElementById('pwd');
        //注册事件 处理程序
        var flag = 0;
        eye.onclick = function(){
            if(flag == 0){
                pwd.type='text';
                eye.src=' ' //修改成开眼的图片
                flag=1;
            }else{
                pwd.type='password'
                eye.src=' '//闭眼的图片
                flag=0;
            }
        }
    </script>
</body>
</html>